package com.example.shopping.authority.controller;

import com.example.shopping.JsonResult;
import com.example.shopping.authority.entity.Role;
import com.example.shopping.authority.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/Mirmission")
public class RoleController {

    @Autowired
    RoleMapper roleMapper;

    @GetMapping("/rolefind")
    //查询所有角色
    public JsonResult getRoleList() {
         List<Role> rolelist= roleMapper.getRoleList();
        return new JsonResult( true,"查询成功",rolelist);
    }

        @GetMapping("/roleselect")
    //根据id查询角色
    public JsonResult getRoleFindList(int roleid) {
        List<Role> rolelist= roleMapper.getRoleFind(roleid);
        return new JsonResult( true,"查询成功",rolelist);
    }

    @PostMapping ("/roleadd")
    //添加一个角色
    public JsonResult getRoleAddList(String rolename,String roledesc) {
        int rolelist= roleMapper.getRoleAddList(rolename,roledesc);
        return new JsonResult( true,"添加成功",rolelist);
    }

    @PostMapping ("/roleupdate")
    //修改一个角色
    public JsonResult getRoleUpdateList(String rolename,String roledesc,int roleid) {
        int rolelist= roleMapper.getRoleUpdateList(rolename,roledesc,roleid);
        return new JsonResult( true,"修改成功",rolelist);
    }

    @GetMapping("/roledel")
    //删除一个角色
    public JsonResult getRoleDelList(int roleid) {
        int rolelist= roleMapper.getRoleDelList(roleid);
        return new JsonResult( true,"删除成功",rolelist);
    }

    @PostMapping ("/roleupjuese")
    //分配角色
    public JsonResult getRoleUpJueSe(String psids,int roleid) {
        int rolelist= roleMapper.getRoleUpJueSeList(psids,roleid);
        return new JsonResult( true,"修改成功",rolelist);
    }
}
